import { defineConfig } from "vite";
//  引入svg需要用到插件
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
//  mock插件提供方法
import { viteMockServe } from "vite-plugin-mock";

import vue from "@vitejs/plugin-vue";
import path from "path";

// https://vitejs.dev/config/
export default defineConfig(({ command }) => {
  return {
    plugins: [
      vue(),
      createSvgIconsPlugin({
        iconDirs: [path.resolve(process.cwd(), "src/assets/icons")],
        symbolId: "icon-[dir]-[name]",
      }),
      viteMockServe({
        //  保证开发阶段可以使用mock接口
        localEnabled: command === "serve",
      }),
    ],
    resolve: {
      alias: {
        "@": path.resolve("./src"),
      },
    },
    server: {
      host: "0.0.0.0",
      proxy: {
        "/api": {
          target: "http://220.249.122.130:90",
          changeOrigin: true,
          rewrite: (path) => path.replace(RegExp(`^api`), ""),
        },
      },
    },
    //  scss全局变量配置
    css: {
      preprocessorOptions: {
        scss: {
          javascriptEnabled: true,
          additionalData: '@import "./src/styles/variable.scss";',
        },
      },
    },
  };
});
